<template>
    <div class=login>
        <div class="login-left">
            <div class="loginLeft-bottom">
                <p>Welcome to</p>
                <p>塞罕云·运营后台管理系统</p>
            </div>
        </div>
        <div class="login-right">
            <div class="login-right-top">
                <img src="../assets/img/index/login-r.png" alt="">
                <span>塞罕云</span>
            </div>
            <p>运营后台管理</p>
            <div class="input">
                <div class="input-name">
                    <img src="../assets/img/index/login-name.png" alt="">
                    <input type="text" placeholder="请输入登录账号" v-model="uname">
                </div>
                <div class="input-name">
                    <img src="../assets/img/index/login-wps.png" alt="">
                    <input type="text" placeholder="请输入您的密码" v-model="upwd">
                </div>
                <!-- <div class="input-name input-upwd">
                    <img src="../assets/img/index/login-wps.png" alt="">
                    <input type="text" placeholder="请输入验证码" v-model="upwd">
                    <span v-if="!isNum" class="getupwd" @click="getupwd">获取验证码</span>
                    <span v-else class="getupwd" style="background:#ccc;">{{num}}</span>
                </div> -->
                <!-- <div v-else class="input-name input-upwd">
                    <img src="../assets/img/index/login-wps.png" alt="">
                    <input type="password" placeholder="请输入密码" v-model="upwd">
                </div> -->

                 <div class="iptTop ">
                    <span class="checkbox" @click="correctNum=!correctNum" :class="{active:correctNum}"><img src="../assets/img/index/login-correct.png" alt=""></span>
                    <span class="rember">记住我</span>
                </div>
            </div>
            <div class="btnLogin">
                <button @click="login">登录</button>
            </div>
        </div>
    </div>
</template>
<script>
export default {
    data(){
        return{
            baseurl:'0',
            uname:'',
            upwd:'',
            correctNum:false,
            num:60,
            isNum:false
        }
    },
    mounted(){
        this.baseurl=this.$store.state.baseurl
        document.onkeydown = event=>{
            var e = event || window.event;
            if (e && e.keyCode == 13) { //回车键的键值为13
                this.login()
            }
        }
        // console.log(1234,sessionStorage.getItem('uname'))
        // if(localStorage.getItem("correctNum")){
        //     this.uname=localStorage.getItem('uname')
        //     this.upwd=localStorage.getItem('upwd')
        //     this.correctNum=localStorage.getItem('correctNum')
        // }
    },
    methods:{
        //获取验证码
        getupwd(){
            var param={
               "phone": this.uname,
               "keyname":'log',
            }
            this.axios({
                url: this.baseurl+"/user/getcode",
                method: "post",
                data: JSON.stringify(param),
            }).then((res)=>{
                this.isNum=true
                var time=setInterval(()=>{
                    if(this.num>0){
                        this.num-=1
                    }else{
                        this.num=60
                        this.isNum=false
                        clearInterval(time);
                    }
                },1000)
            })
        },
        // 登录
        login(){
            if(this.uname=='admin'&&this.upwd=='admin'){
                var token='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzY3MTA4NjAsInVzZXJfaWQiOjE0NSwidXNlcl9waG9uZSI6IjE4MzMwMjE3NDA1IiwidXNlcl9uaWNrIjoi5bCP6aW85bmyIiwidXNlcl9pb2MiOiJodHRwczovL2NrbGNvay5vc3MtY24temhhbmdqaWFrb3UuYWxpeXVuY3MuY29tL3VzZXJpY28vMTQ1LnBuZyIsInJlY29tbWVuZF91c2VyIjowfQ.7fmVJ1CgyBMKY0e9SL5k1p3-hjYZR-kRKRMWmAtTqZ4'
                sessionStorage.setItem('token',token);
                sessionStorage.setItem('uname',this.uname);
                sessionStorage.setItem('correctNum',this.correctNum);
                sessionStorage.setItem('islogin',true);
                this.$router.push({path:'index'})
            }
            // this.axios({
            //     url:this.baseurl+'/user/login',
            //     method:'post',
            //     data:{logtype:'phone',logkey:this.uname,code:this.upwd},
            // }).then(res=>{
            //     if (res.data.status==200){
            //         sessionStorage.setItem('token',res.data.token);
            //         sessionStorage.setItem('uname',this.uname);
            //         sessionStorage.setItem('correctNum',this.correctNum);
            //         sessionStorage.setItem('islogin',true);
            //         this.$router.push({path:'index'})
            //     }else if (res.data.code==201) {
            //         alert(res.data.message);
            //     }
            // })
            // this.axios.post('',{uname:this.uname,upwd:this.upwd}).then(res => {
            //     console.log(res)
            //     if(res.data.code==200){
            //         alert('登录成功')
            //         sessionStorage.setItem('islogin',true);
            //         sessionStorage.setItem('uname',this.uname);
            //         sessionStorage.setItem('upwd',this.upwd);
            //         sessionStorage.setItem('correctNum',this.correctNum);
            //         if(this.correctNum){
            //             localStorage.setItem("uname", this.uname);
            //             localStorage.setItem("upwd", this.upwd);
            //         }else{
            //             localStorage.setItem("uname", '');
            //             localStorage.setItem("upwd", '');
            //         }
            //         var payload=res.data
            //         payload.uname=this.uname
            //         payload.upwd=this.upwd
            //         payload.correctNum=this.correctNum
            //         this.$store.commit('login_mutation',payload)
            //         this.$router.push({path:'index'})
            //     }else{
            //         alert('登录失败')
            //     }
            // })
        },
    }
}

</script>
<style scoped>
.login{
    display: flex;
    min-width: 1200px;
}
.login-left{
    width: 58%;
    height: 100vh;
    background: url('../assets/img/index/login-l.png');
    background-size: 100% 100%;
    position: relative;
}
.loginLeft-bottom{
    position: absolute;
    bottom: 36px;
    left: 36px;
    color: #fff;
    font-size: 36px;
    letter-spacing:6px;
}
.loginLeft-bottom p:first-child{
    color:rgba(253, 191, 94, 1);
    margin-bottom: 2px;
}
.login-right{
    width:42%;
    padding: 90px;
    padding-top: 150px;
}
.login-right-top{
    color: #44566C;
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-right-top img{
    width: 66px;
    height: 66px;
    margin-right: 20px;
}
.login-right-top span{
    margin-top: -10px;
    font-size: 60px;
    letter-spacing: 5px;
}
.login-right p{
    text-align: center;
    color: #8697A8;
    margin-top: 55px;
    margin-bottom: 33px;
    letter-spacing: 2px;
    font-size: 20px;
}
.login-right .input input{
    display: block;
    width: 100%;
    border: 1px solid #f2f2f2;
    background: #F8FAFB;
    font-size: 16px;
    padding: 0 0px 0 45px;
    outline: 0;
    height: 45px;
}
.input-name{
    margin-top: 20px;
    position: relative;
}
.input-name img{
    width: 20px;
    height: 20px;
    position: absolute;
    top: 50%;
    transform: translatey(-50%);
    left: 12px;
}
.input-upwd{
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: space-between;
}
.input-upwd .getupwd{
    width: 160px;
    margin-left: 10px;
    height:42px;
    background: rgba(255, 218, 59, 1);
    color: #fff;
    border-radius: 2px;
    line-height: 42px;
    text-align: center;
}
.iptTop{
    display: flex;
    align-items: center;
    margin-top: 20px;
}
.rember{
    font-size: 15px;
    color: #444;
    margin: 0 0 0 10px;
}
.btnLogin{
    width: 100%;
    margin:40px auto 0;
}
.btnLogin button{
    background: rgba(255, 218, 59, 1);
    height: 45px;
    line-height: 40px;
    text-align: center;
    font-size: 18px;
    color: #ffffff;
    width: 100%;
    border: none;
    border-radius: 5px;
    outline: 0;
}
.btnLogin button::after{
    border: none;
}
.iptTop .checkbox{
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: 1px solid #ddd;
    position: relative;
}
.iptTop .checkbox img{
    width: 15px;
    height: 15px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
}
.iptTop .active{
    background:rgba(255, 218, 59, 1) ;
}
</style>